

using System;
using System.Collections.Generic;
using System.Text;

namespace JTC.MiniCommerce.Store {
  public partial class Product {
  
    #region Member Variables

    private string _defaultImagePath = null;
    
    #endregion
    
    #region Properties

    /// <summary>
    /// Gets the rating.
    /// </summary>
    /// <value>The rating.</value>
    public int Rating {
      get {
        return this.RatingSum / this.TotalRatingVotes;
      }
    }

    /// <summary>
    /// Gets the default image path.
    /// </summary>
    /// <value>The default image path.</value>
    public string DefaultImagePath {
      get {
        if(_defaultImagePath == null) {
          ImageCollection imageCollection = this.ImageRecords();
          if(imageCollection.Count > 0) {
            imageCollection.Sort(Image.Columns.SortOrder, true);
            _defaultImagePath = imageCollection[0].ImageFile;
          }
          else {
            _defaultImagePath = string.Empty;
          }
        }

        return _defaultImagePath;
      }
    }

    /// <summary>
    /// Gets the you save amount.
    /// </summary>
    /// <value>The you save amount.</value>
    public decimal YouSaveAmount {
      get {
        return (this.RetailPrice - this.OurPrice);
      }
    }

    /// <summary>
    /// Gets the you save percentage.
    /// </summary>
    /// <value>The you save percentage.</value>
    public decimal YouSavePercentage {
      get {
        return ((this.RetailPrice - this.OurPrice) / this.OurPrice);
      }
    }
    
    #endregion
	
  }
}
